package dk.hewison.client.pages;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Widget;
import dk.hewison.client.mvc.AbstractView;
import dk.hewison.client.mvc.Action;
import dk.hewison.client.mvc.widgets.MButton;

/**
 * @author John Hewison
 * @author $LastChangedBy: john.hewison $:  $ $LastChangedDate: 2009-02-01 11:48:14 +0000 (Sun, 01 Feb 2009) $:
 * @version $Revision: 65 $:
 */
public class MainMenuView extends AbstractView<MenuItem[]> {
    Grid grid;


    public MenuItem[] getModel() {
        return new MenuItem[0];
    }

    public void setModel(MenuItem[] menuItems) {

        grid.resize(1, menuItems.length);

        Action[] actions = controller.getActions();
        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];
            grid.setWidget(0, i, new Button(action.getText()));
        }

        /*for (int i = 0; i < menuItems.length; i++) {
            final int page = i;
            MenuItem menuItem = menuItems[i];
            Button widget = new Button(menuItem.name);
            widget.addClickListener(new ClickListener() {
                public void onClick(Widget sender) {
                    controller.getAction()
                    //pageStackView.showPage(page);
                }
            });
            widget.setWidth("100%");
            widget.setHeight("40px");
            //setWidget(0, i, widget);
        }*/
    }

    public void initView() {
        Action[] actions = controller.getActions();
        grid = new Grid(1, actions.length);
        for (int i = 0; i < actions.length; i++) {
            Action action = actions[i];
            grid.setWidget(0, i, new MButton(action));
        }
    }


    public Widget getMyWidget() {
        return grid;
    }
}
